<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_select">
        <div class="input">
          <el-select v-model="dataForm.category" :placeholder="$t('common.please_select') + $t('member.invoice.category')" clearable>
            <el-option :label="$t('common.all')" value=""></el-option>
            <el-option v-for="(v, k) in invoiceCategoryList" :label="v.text" :key="k" :value="v.value">
            </el-option>
          </el-select>
        </div>
        <div class="input">
          <el-select v-model="dataForm.type" :placeholder="$t('common.please_select') + $t('member.invoice.type')" clearable>
            <el-option :label="$t('common.all')" value=""></el-option>
            <el-option v-for="(v, k) in invoiceTypeList" :label="v.text" :key="k" :value="v.value">
            </el-option>
          </el-select>
        </div>
        <div class="input">
          <el-input
            v-model="dataForm.code"
            :placeholder="i18n('common.please_input') + i18n('member.invoice.code')"
            clearable>
          </el-input>
        </div>
        <div class="input">
          <el-input
            v-model="dataForm.name"
            :placeholder="i18n('common.please_input') + i18n('member.invoice.name')"
            clearable>
          </el-input>
        </div>
        <div class="input">
          <el-select v-model="dataForm.audit_status" :placeholder="$t('common.please_select') + $t('common.audit_status')" clearable>
            <el-option :label="$t('common.all')" value=""></el-option>
            <el-option v-for="(v, k) in auditStatusList" :label="v.text" :key="k" :value="v.value">
            </el-option>
          </el-select>
        </div>
        <div class="date">
          <el-date-picker v-model="dataForm.create_time" type="daterange" :range-separator="$t('common.to')" :start-placeholder="$t('common.start_time')" :end-placeholder="$t('common.end_time')" clearable>
          </el-date-picker>
        </div>
        <div class="input">
          <el-button icon="Search" @click="getDataList(true)">
            {{ i18n('common.search') }}
          </el-button>
        </div>
      </div>

      <div class="admin_table_main">
        <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle" stripe>
          <el-table-column type="selection" header-align="center" align="center">
          </el-table-column>

          <el-table-column prop="id" :label="i18n('common.id')" fixed="left" width="70">
          </el-table-column>

          <el-table-column :label="i18n('member.invoice.nickname')" width="280">
            <template v-slot="scope">
              <dl class="table_dl" v-if="scope.row.member">
                <dt>
                  <el-image class="cx-list-image" :src="scope.row.member.avatar" loading="lazy" lazy>
                    <template #error>
                      <div class="image-slot">
                        <el-icon><Picture /></el-icon>
                      </div>
                    </template>
                  </el-image>
                </dt>
                <dd class="table_dl_dd_all_30">
                  {{ scope.row.member.chinese_nickname }}
                </dd>
                <dd class="table_dl_dd_all_16_gray">
                  {{ scope.row.member.username }}
                </dd>
              </dl>
            </template>
          </el-table-column>

          <el-table-column :label="i18n('member.invoice.category')" width="140">
            <template v-slot="scope">
              <el-text>
                {{ scope.row.category.text }}
              </el-text>
            </template>
          </el-table-column>

          <el-table-column :label="i18n('member.invoice.type')" width="80">
            <template v-slot="scope">
              <el-text>
                {{ scope.row.type.text }}
              </el-text>
            </template>
          </el-table-column>

          <el-table-column prop="code" :label="i18n('member.invoice.code')" width="180">
          </el-table-column>

          <el-table-column prop="name" :label="i18n('member.invoice.name')">
          </el-table-column>

          <el-table-column prop="email" :label="i18n('member.invoice.email')" width="220">
          </el-table-column>

          <el-table-column :label="i18n('common.audit_status')" width="80">
            <template v-slot="scope">
              <el-text>
                {{ scope.row.audit_status.text }}
              </el-text>
            </template>
          </el-table-column>

          <el-table-column prop="create_time" :label="i18n('common.create_time')" width="160">
          </el-table-column>

          <el-table-column :label="i18n('common.handle')" fixed="right" width="100">
            <template v-slot="scope">
              <el-button
                v-if="isAuth('module:member:invoice:form') && scope.row.audit_status.value != 1"
                type="warning"
                icon="ZoomIn"
                @click="router.push({ name: 'module_member_invoice_form', query: { id: scope.row.id } })">
                {{ i18n('common.audit') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>

        <div class="admin_table_main_pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :page-size="pageSize"
            :total="totalPage"
            :current-page="pageIndex"
            background
            layout="prev, pager, next,jumper,total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="member-invoice-list">
  import { useBase } from "@/hooks/base/useBase"
  import { useTable } from "@/hooks/table/useTable"

  const { router, i18n, isAuth } = useBase()

  const model = ref('member/invoice')

  const invoiceCategoryList = ref([])
  const invoiceTypeList = ref([])
  const auditStatusList = ref([])

  const dataForm = reactive([
    'category',
    'type',
    'code',
    'name',
    'audit_status',
    'create_time',
  ])

  const {
    dataList,
    pageIndex,
    pageSize,
    totalPage,
    dataListLoading,
    sizeChangeHandle,
    currentChangeHandle,
    selectionChangeHandle,
    getDataList,
    deleteHandle,
  } = useTable(model.value, dataForm)


  /**
   * @author zhangxiaofei [<1326336909@qq.com>]
   * @dateTime 2024-05-30
   *
   * 获取发票类型信息
   *
   * @return {[type]}
   */
  const loadInvoiceCategoryList = () => {
    $http({
      url: $http.adornUrl('/dictionary/data'),
      method: 'get',
      params: $http.adornParams({
        title: 'invoice_category',
      }),
    }).then(({data}) => {
      if (data && data.status === 200) {
        invoiceCategoryList.value = data.data
      } else {
        $message.error(data.message)
      }
    })
  }


  /**
   * @author zhangxiaofei [<1326336909@qq.com>]
   * @dateTime 2024-05-30
   *
   * 获取发票类型信息
   *
   * @return {[type]}
   */
  const loadInvoiceTypeList = () => {
    $http({
      url: $http.adornUrl('/dictionary/data'),
      method: 'get',
      params: $http.adornParams({
        title: 'invoice_type',
      }),
    }).then(({data}) => {
      if (data && data.status === 200) {
        invoiceTypeList.value = data.data
      } else {
        $message.error(data.message)
      }
    })
  }


  /**
   * @author zhangxiaofei [<1326336909@qq.com>]
   * @dateTime 2024-05-30
   *
   * 获取审核状态信息
   *
   * @return {[type]}
   */
  const loadAuditStatusList = () => {
    $http({
      url: $http.adornUrl('/dictionary/data'),
      method: 'get',
      params: $http.adornParams({
        title: 'audit_status',
      }),
    }).then(({data}) => {
      if (data && data.status === 200) {
        auditStatusList.value = data.data
      } else {
        $message.error(data.message)
      }
    })
  }


  onMounted(() => {
    getDataList(model)

    loadInvoiceCategoryList()
    loadInvoiceTypeList()
    loadAuditStatusList()
  })
</script>
